<?php
namespace Home\Controller;
use Think\Controller;

class IndexController extends CommonController {

    public function index(){
//        dump(22);
        $news = M('news');
        $cate = M('cate');
        $link = M('link');
        // 最新动态
        $where['pid'] = array('not in','44,5,36,37,38,39,40,41,42,43');
        $data['hotnews'] = $news->order('id desc')->where($where)->limit(6)->select();
        // 产品分类
        $news_cate = $cate->where('level = 2')->limit(6)->select();
        foreach($news_cate as $k=>$v){
            $news_cate[$k]['child_cate'] = $cate->where("level = 3 and pid = ".$v['id'])->select();
        }
//        dump($news_cate);
        $data['news_cate'] = $news_cate;
        // 热门推荐
        $map1pid = get_idchild(1); //农业种植下的二级分类
        $map2pid = get_idchild(2); //农业养殖下的二级分类
        $map1['pid']  = array('in',$map1pid);
        $map2['pid']  = array('in',$map2pid);
        $data['zznews'] = $news->where($map1)->order('id desc')->limit(6)->select();
        $data['yznews'] = $news->where($map2)->order('id desc')->limit(6)->select();
        // 最新政策
        $data['zcnews'] = $news->where("pid = 5")->order('id desc')->limit(6)->select();
        // 企业新闻
        $data['qynews'] = $news->where("pid = 44")->order('id desc')->limit(6)->select();
        // 资讯导航
        $huahui = $cate->where('pid = 8')->select();
        foreach ($huahui as $k=>$v){
            $zxnews[$k]['zxnews_list'] = $news->where("pid = ".$v['id'])->field('id,title')->select();
        }
        $data['zxnews'] = $zxnews;
//        dump($data['zxnews']);
        // 友情链接
        $data['link'] = $link->select();
        $data['head_title'] = "乡土味士农业资讯站";
        $data['keywords'] = "乡土味士农业资讯站";
        $data['description'] = "乡土味士农业资讯站";
        //电脑端轮播图
        $data['banner'] = M('advert')->where("type=0 and place=1")->select();
        if(is_mobile()){
            $data['banner'] = M('advert')->where("type=0 and place=0")->select();
        }
        $this->assign($data);
        if(is_mobile()){
            $this->display("index-h5");//手机端
        }else{
            $this->display('index');//PC端
        }// end if

    }// end fun

}// end class
